﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MrPP.Myth;
using GDGeek;
using MrPP.Common;
using MrPP.Tracking;
using MrPP.UX;
using System;

namespace MrPP.SerriedCabinet
{
    public class ProcessBridging : MonoBehaviour
    {

        [SerializeField]
        private string _url = "http://192.168.1.108:3000/geek/A/01";
        [SerializeField]
        private VuforiaMark.Mark _mark = VuforiaMark.Mark.Mark8;
        [SerializeField]
        private SearchWindow _search;
        public SearchWindow search
        {
            get
            {
                return _search;
            }
        }
        void Start()
        {



            QRCodeManager.Instance.onRecevie += this.doQrcode;
            QRCodeManager.Instance.open();
            TrackingHandler handler = this.gameObject.AskComponent<TrackingHandler>();
            handler.addMaker(this._mark);
            handler.onFind += this.doAnchor;
            _search.OnInput += doScreenInput;
            _search.onSelected += doScreenSelected;

        }
        public void testScanning()
        {
          //  Debug.LogError("!!!");
            //
            doQrcode(_url);
            doAnchor(AnchorTest.Instance.transform);
        }

       
        void OnDetory()
        {
            TrackingHandler handler = this.gameObject.AskComponent<TrackingHandler>();
            GameObject.DestroyImmediate(handler);
            QRCodeManager.Instance.close();
            QRCodeManager.Instance.onRecevie -= this.doQrcode;
            _search.OnInput -= doScreenInput;
            _search.onSelected -= doScreenSelected;

        }
        public void doAnchor(Transform trans)
        {
            MrPP.MVC.PostToServer.Instance.post(new AsgardPoseMessage("anchor", trans.gameObject));
        }
        public void doQrcode(string url)
        {
            _url = url;
            MrPP.MVC.PostToServer.Instance.post(new StringMessage("qrcode", url));
        }


        private void doScreenSelected(int id)
        {
          //  SerriedCabinetPost.Instance.doScreenSelected(id);
            MrPP.MVC.PostToServer.Instance.post("screen_selected", id);
        }

  
        public void doVentilate()
        {
            MrPP.MVC.PostToServer.Instance.post("ventilate");

        }

        public void doStop()
        {

            MrPP.MVC.PostToServer.Instance.post("stop");
        }
        public void doClose()
        {

            MrPP.MVC.PostToServer.Instance.post("close");
        }

        public void doOpen()
        {
            MrPP.MVC.PostToServer.Instance.post("open");
        }

        public void doSelect(IntId id)
        {
            MrPP.MVC.PostToServer.Instance.post("select", id.id);

        }
      
        public void doOpenSecond(int id)
        {
        //    Debug.LogError("open:" + id);
            MrPP.MVC.PostToServer.Instance.post("open_second", id);
        }
        public void doScreenGuide()
        {
            MrPP.MVC.PostToServer.Instance.post("screen_guide");
        }
        public void doScreenClear()
        {
            MrPP.MVC.PostToServer.Instance.post("screen_clear");
        }
        public void addLetter(string letter)
        {
            MrPP.MVC.PostToServer.Instance.post("screen_add_letter", letter);
        }
        public void doScreenInput(string input)
        {
           
            MrPP.MVC.PostToServer.Instance.post("screen_input", input);
        }
        public void doScreenSearch()
        {

            MrPP.MVC.PostToServer.Instance.post("screen_search");
        }

       
    }
}